<template>
    <div class='listComplex' v-loading="loading">
       
         <div v-if="isDevOps=='Y'" class="list_dev">
            <common-list-double style="flex:1" :isApp="isApp"  :isTitle="isTitle"  @loadDatad="loadDatad" @loadDatad2="loadDatad2" @loadDataMaind="loadDataMaind" ref="commonList"  :sKey="sKey" :sOtherKey="sOtherKey" :model="model"  :exKey="exKey" :company="company" :appid="appid"   :listname="listname" :model_key="key" @rowDbClick="rowDbClick"></common-list-double>
           <list-dev style="flex:1;overflow:hidden;" :company="company" :filepath="filepath"  :filepath2="filepath2" :filepath3="filepath3" :isDevOps="isDevOps" v-if="isDevOpsShow=='Y'" @loadData="devLoadData"></list-dev>  
        </div>
        <template v-else>
            <common-list-double  :isApp="isApp"  :isTitle="isTitle"  @loadDatad="loadDatad" @loadDatad2="loadDatad2" ref="commonList"  :sKey="sKey" :sOtherKey="sOtherKey" :model="model"  :exKey="exKey" :company="company" :appid="appid"   :listname="listname" :model_key="key" @rowDbClick="rowDbClick"></common-list-double>
      
        </template> 
        <el-dialog
                v-el-drag-dialog
                :title="commonEditData.title"
                :modal="false"
                class="dialogClass dialog-vertical"
                style='left:0;top:0'
                center
                :visible.sync="dialogVisible3"
                >
                <common-edit :commonEditData="commonEditData"   @openWin="openWin2" @closeWin="closeWins" @goSearch="goSearch" v-if="dialogVisible3"></common-edit>
                
            </el-dialog>
    </div>
</template>
<script>
import commonListDouble  from '../components/list/commonListDouble.vue'
import CommonEdit  from './CommonEdit.vue'
import ListDev  from '../components/dev/listDev.vue'
export default {
    name:'listDouble',
    components: {
        commonListDouble,
        CommonEdit,
        ListDev
    },
    data(){
        return{
              commonEditData:{
                fieldPath:"",
                filename2:"",
                sId:"",
                param_key:"",
                appid:"",
                title:""
            },
            isDevOps:"",
            isDevOpsShow:"",
            filepath:"",
            filepath2:"",
            filepath3:"",
            sKey:'',
            sOtherKey:'',
            exKey:'',
            loading:true,
            company:'',
            appid:'',
            listname:"",
            key:'',
            model:"",
            dialogVisible3:false,
            isApp:'',
            isTitle:""
        }
    },
    created(){
        if(sessionStorage.getItem("isDevOps")=="Y"){
            this.isDevOps="Y"
        }
         let sef=this;
         window.addEventListener('message', function(messageEvent) {
           sef.goSearch();
       
        },false);
        if(this.$route.query.isApp){
            this.isApp=this.$route.query.isApp;
        }
        if(this.$route.query.sKey){
            this.sKey=this.$route.query.sKey;
        }
        if(this.$route.query.sOtherKey){
            this.sOtherKey=this.$route.query.sOtherKey;
        }
        if(this.$route.query.company){
            this.company=this.$route.query.company;
        }
        if(this.$route.query.exKey){
            this.exKey=this.$route.query.exKey;
        }
        if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }
        if(this.$route.query.listname){
            this.listname=this.$route.query.listname;
        }
        if(this.$route.query.key){
            this.key=this.$route.query.key;
        }
        if(this.$route.query.model){
            this.model=this.$route.query.model;
        }
        this.loading=false;
    
    } ,
     methods:{
        loadDatad(data){
            this.filepath=data;
            if(sessionStorage.getItem("isDevOps")=="Y"&&this.filepath&&this.filepath2)
                this.isDevOpsShow="Y"
           
        },
        loadDatad2(data){
            this.filepath2=data;
            if(sessionStorage.getItem("isDevOps")=="Y"&&this.filepath&&this.filepath2)
                this.isDevOpsShow="Y"
          
        },
        loadDataMaind(data){
            this.filepath3=data;
            if(sessionStorage.getItem("isDevOps")=="Y"&&this.filepath&&this.filepath2)
                this.isDevOpsShow="Y"
           
        },
        devLoadData(data){
            
            this.$refs.commonList.loadData("Y");
        },
        openWin(data){
           /* let datas=JSON.parse(data);
            let wb_msg=datas.wb_msg;
            
            console.log(datas)
            
            this.$emit("openWin",data)*/


            if(this.isApp!="Y"){
                 let datas=JSON.parse(data);
                let wb_msg=datas.wb_msg;
                
                console.log(datas)
                this.$emit("openWin",data)
            }else{
                let item=JSON.parse(data);
                this.dialogVisible3=true;
            
                this.commonEditData={
                    fieldPath:"",
                    filename2:"",
                    sId:"",
                    param_key:"",
                    appid:"",
                    title:"",
                    paramVals:''
                };
                this.commonEditData.fieldPath=item.fieldPath;
                this.commonEditData.filename2=item.filename2;
                this.commonEditData.appid=item.appid;
                this.commonEditData.param_key=item.param_key;
                this.commonEditData.title=item.buttonName;
                this.commonEditData.paramVals=item.paramVals;
                this.commonEditData.sId=item.sId;
                let els=document.getElementsByClassName("el-dialog");
                for(let i=0;i<els.length;i++){
                    els[i].style.left="0";
                    els[i].style.top="0"
                }
            }
           //  parent.postMessage(data,'*');
            
        },
        closeWins(datas){
            this.dialogVisible3=false;
        },
         goSearch(){
            this.$refs.commonList.goSearch();
        },
        getScrollTop(){
            return this.$refs.commonList.getScrollTop();
        },
        setScrollTop(top){
            this.$refs.commonList.setScrollTop(top);
        },
        initData(){
            this.$refs.commonList.initData();
        },
        rowDbClick(data){
            let rows=JSON.parse(data);
            console.log(rows,"rows===============")
            if(rows.dbModelkey){
                
                this.$post("api","api/view/getDbUrl",{key:escape(rows.dbModelkey)}).then(data=>{
                    let name=data.name;
                    let sId=rows[data.fieldKey];
                    let url=data.url;
                    let field=data.field;
                    let filename=data.filename;
                    let param="sId="+sId+"&appid="+this.appid+"&filename2="+filename+"&fieldPath="+field;
                    url=url.indexOf("?")==-1 ? url+"?"+param:url+"&"+param;
                    let item={};
                    item.buttonName=name;
                    item.url=url;
                    
                    item.sId=sId;
                    item.appid=this.appid;
                    item.filename2=filename;
                    item.fieldPath=field;
                    this.openWin(JSON.stringify(item))
                })
            }
        }
    }
}
</script> 
<style scoped>
    .listComplex{
        height:100%;
        width:100%;
      
    } 
    
    .list_dev{
        height:100%;
        width:100%;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        padding:0;
        padding-top:0;
        display:flex;
        flex-direction:row;
    }
</style>